HW5 20225421 Dahee Kwon

Refocusing and focal-stack generation

custom_stack = cell(5,1);
custom_stack{1} = imread('./custom/custom1.jpeg');
custom_stack{2} = imread('./custom/custom2.jpeg');
custom_stack{3} = imread('./custom/custom3.jpeg');
custom_stack{4} = imread('./custom/custom4.jpeg');
custom_stack{5} = imread('./custom/custom5.jpeg');

All-focus image and depth from defocus

sigma1 = 0.5;
sigma2 = 1;
 
fstack_lum = cell(5,1);
fstack_low = cell(5,1);
fstack_high = cell(5,1);
wsharp = cell(5,1);
%1
for i = 1:5
tmp = rgb2xyz(custom_stack{i});
fstack_lum{i} = tmp(:,:,2);
end
%2
for i = 1:5
tmp = im2double(imgaussfilt(fstack_lum{i},sigma1));
fstack_low{i} = tmp;
end
%3
for i=1:5
fstack_high{i} = fstack_lum{i} - fstack_low{i};
end
%4
for i = 1:5
tmp = im2double(imgaussfilt((fstack_high{i}).^2,sigma2));
wsharp{i} = tmp;
end
nom = 0; denom = 0;
for i = 1:5
nom = nom + wsharp{i}.*im2double(custom_stack{i});
denom = denom + wsharp{i};
end
focused_img = nom./denom;
 
imshow(focused_img)
nom = 0; denom = 0;
d_list = {0.2,0.4,0.6,0.8,1};
for i = 1:5
nom = nom + wsharp{i}.*abs(d_list{i});
denom = denom + wsharp{i};
end
depthmap = nom./denom;
imshow(depthmap)